let app  = getApp();
let util = {
    showToast: function(t) {
        var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "none", n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : 1500;
        wx.showToast({
            title: t,
            icon: e,
            duration: n,
            mask: !0
        });
    },
    getStepCount: 0,
    getWechatStep: function(n, a) {
        var o = this;
        wx.getWeRunData({
            success: function(r) {
                const encryptedData = r.encryptedData
                //console.log(app.openid)
                wx.request({
                    url: app.domain + "ssm/appWebServ/saveStepInfo",
                    data: {
                        data: r,
                        openid: app.openid
                    },
                    header: {
                        'content-type': 'application/json' // 默认值
                    },
                    success(res) {
                        //console.log(app.openid)
                        wx.request({
                            url: app.domain + "ssm/appWebServ/feet/getStepInfo",
                            header: {
                                'content-type': 'application/json'
                            },
                            data: {
                                openid: app.openid,
                            },
                            success: function(res) {
                                console.log(res)
                                if(res.data.respCode==0){
                                    return a(res.data.stepInfo.total_cur_step)
                                }
                                // if(res.code == 1) {
                                //     wx.getWeRunData({
                                //         success: function(s) {
                                //             wx.request({
                                //                 url: "XwyAppPage/phonedecryption",
                                //                 data: {
                                //                     encryptedData: s.encryptedData,
                                //                     iv: s.iv,
                                //                     openid: res.data.openid
                                //                 },
                                //                 success: function(t) {
                                //                     // todo
                                //                     if (console.log("接口解密结果：", t), !t.get_encrydata || !t.get_encrydata.stepInfoList || !t.get_encrydata.stepInfoList.length) return o.getStepCount++, 
                                //                     o.getStepCount >= 3 ? a && a(-1) : o.getWechatStep(n, a), !1;
                                //                     o.getStepCount = 0;
                                //                     var e = t.get_encrydata.stepInfoList[t.get_encrydata.stepInfoList.length - 1].step;
                                //                     31 === n && (e = t.get_encrydata.stepInfoList), a && a(e);
                                //                 }
                                //             });
                                //         },
                                //         fail: function() {
                                //             a && a(-1);
                                //         }
                                //     })
                                // }
        
                            },
                            fail: function(t) {
                                console.log(t), a && a(-1);
                            }
                        });
                    },
                    complete(r) {

                    }
                })
            },
            fail: function(t) {
                console.log(t), a && a(-1);
            }
        });
    },
    getWeek: function(t) {
        return [ "周日", "周一", "周二", "周三", "周四", "周五", "周六" ][new Date(t).getDay()];
    },
    getTeamList: function(n) {
        var a = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
        if (e.teamList && !a) return n(), !1;
        t.default.ajax({
            url: "redpackshop/shopcatelist",
            data: {
                who: e.who,
                catetypes: 3
            },
            success: function(t) {
                t.shopcatelist && (e.teamList = t.shopcatelist), n();
            }
        });
    },
    compareVersion: function(t, e) {
        t = t.split("."), e = e.split(".");
        for (var n = Math.max(t.length, e.length); t.length < n; ) t.push("0");
        for (;e.length < n; ) e.push("0");
        for (var a = 0; a < n; a++) {
            var o = parseInt(t[a]), r = parseInt(e[a]);
            if (o > r) return 1;
            if (o < r) return -1;
        }
        return 0;
    },
    formateSeconds: function(t) {
        var e = parseInt(t), n = 0, a = 0;
        return e > 60 && (n = parseInt(e / 60), e = parseInt(e % 60), n > 60 && (a = parseInt(n / 60), 
        n = parseInt(n % 60))), a < 10 && (a = "0" + a), n < 10 && (n = "0" + n), e < 10 && (e = "0" + e), 
        a + ":" + n + ":" + e;
    },
    getDay: function() {
        var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 0, e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "-", n = new Date(), a = n.getTime() + 864e5 * t;
        n.setTime(a);
        var o = n.getFullYear(), r = n.getMonth(), s = n.getDate();
        switch (r = this.doHandleMonth(r + 1), s = this.doHandleMonth(s), e) {
          case "-":
            return o + "-" + r + "-" + s;

          case "/":
            return o + "/" + r + "/" + s;

          case "年月日":
            return o + "年" + r + "月" + s + "日";

          case "":
            return o + r + s;
        }
    },
    doHandleMonth: function(t) {
        var e = t;
        return 1 == t.toString().length && (e = "0" + t), e;
    },
    unitTimeToDate: function(t) {
        var e = arguments.length > 1 && void 0 !== arguments[1] && arguments[1], n = new Date(1e3 * t), a = n.getFullYear(), o = n.getMonth() + 1;
        o < 10 && (o = "0" + o);
        var r = n.getDate();
        r < 10 && (r = "0" + r);
        var s = n.getHours();
        s < 10 && (s = "0" + s);
        var i = n.getMinutes();
        i < 10 && (i = "0" + i);
        var u = n.getSeconds();
        u < 10 && (u = "0" + u);
        var c = a + "-" + o + "-" + r, g = s + ":" + i + ":" + u;
        return e ? c + " " + g : c;
    }
};

module.exports = util;